package com.wgts.wgts.mvp.presenter.imp;

import com.wgts.wgts.mvp.model.IMyOrderDetailsActivityModel;
import com.wgts.wgts.mvp.presenter.IMyOrderDetailsActivityPresenter;
import com.wgts.wgts.mvp.view.IMyOrderDetailsActivityView;
import com.wgts.wgts.netmodle.HttpResultSubscriber;
import com.wgts.wgts.netmodle.resp.ChangeGoodsPlanEntity;
import com.wgts.wgts.netmodle.resp.CurrentEntity;
import com.wgts.wgts.netmodle.resp.MyOrderDetailsEntity;

import java.util.ArrayList;
import java.util.List;

/*
 *
 *   data:2018/10/914:29
 *
 */public class MyOrderDetailsActivityPresenter implements IMyOrderDetailsActivityPresenter {
     private IMyOrderDetailsActivityView view;
     private IMyOrderDetailsActivityModel model;
     //店铺列表
     private List<MyOrderDetailsEntity.Shop> storeList;

    public MyOrderDetailsActivityPresenter(IMyOrderDetailsActivityView view, IMyOrderDetailsActivityModel model) {
        this.view = view;
        this.model = model;
    }

    @Override
    public void orderDetailsResult(int orderId) {
        model.orderDetailsResult(orderId, new HttpResultSubscriber<MyOrderDetailsEntity>() {
            @Override
            public void onSuccess(MyOrderDetailsEntity myOrderDetailsEntity) {
                storeList = new ArrayList<>();
                storeList = myOrderDetailsEntity.shops;
                view.orderDetailsResult(myOrderDetailsEntity);
            }

            @Override
            public void _onError(int status, String msg) {
                view.onError(status, msg);
            }
        });
    }

    @Override
    public void getListDate(boolean isALl) {
        if (isALl){
                for (int i = 0; i < storeList.size(); i++){
                        storeList.get(i).show = true;
                    for (int j = 0; j < storeList.get(i).products.size(); j++){
                        storeList.get(i).products.get(j).show = true;
                    }
                }
            }else {
                    for (int i = 0; i < storeList.size(); i++){
                        storeList.get(i).show = false;
                        for (int j = 0; j < storeList.get(i).products.size(); j++){
                            storeList.get(i).products.get(j).show = false;
                        }
                    }
                    storeList.get(0).show = true;
                    storeList.get(0).products.get(0).show = true;
            }
        view.getListDate(storeList);
    }

    @Override
    public void changeOrderPlan(Integer orderId) {
        model.changeOrderPlan(orderId, new HttpResultSubscriber<List<ChangeGoodsPlanEntity>>() {
            @Override
            public void onSuccess(List<ChangeGoodsPlanEntity> changeGoodsPlanEntities) {
                view.changeOrderPlan(changeGoodsPlanEntities);
            }

            @Override
            public void _onError(int status, String msg) {
                view.onError(status, msg);
            }
        });
    }

    @Override
    public void cancelOrder(String orderId) {
        model.cancelOrder(orderId, new HttpResultSubscriber<CurrentEntity>() {
            @Override
            public void onSuccess(CurrentEntity currentEntity) {
                view.changeOrderType();
            }

            @Override
            public void _onError(int status, String msg) {
                view.onError(status, msg);
            }
        });
    }

    @Override
    public void takeGoods(String orderId) {
        model.takeGoods(orderId, new HttpResultSubscriber<CurrentEntity>() {
            @Override
            public void onSuccess(CurrentEntity currentEntity) {
                view.changeOrderType();
            }

            @Override
            public void _onError(int status, String msg) {
                view.onError(status, msg);
            }
        });
    }
}
